
package data;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class EditarCursosAction extends org.apache.struts.action.Action {

    private static final String SUCCESS = "success";

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if (form != null) {
            EditarCursosForm nameForm = (EditarCursosForm) form;
            String sigla = request.getSession().getAttribute("Sigla").toString();
            String nombre = nameForm.getNombre();
            String creditos = nameForm.getCreditos();
            EditarCursosGateway gw = new EditarCursosGateway();
            gw.actualizarCurso(sigla, nombre, creditos);
            
            String r1 = nameForm.getR1();
            String r2 = nameForm.getR2();
            String r3 = nameForm.getR3();
            if(r1 != "-"){
                gw.agregarRequisito(sigla, r1);
            }
            if(r2 != "-"){
                gw.agregarRequisito(sigla, r2);
            }
            if(r3 != "-"){
                gw.agregarRequisito(sigla, r3);
            }
        }
        return mapping.findForward(SUCCESS);
    }
}
